﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Store
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    public class 物料品种查询 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.CacheControl = "no-cache";
            context.Response.Expires = -1;

            string s = context.Request["s"];
            //context.Response.Write(context.Request.ContentLength+ context.Request.ContentType + " s=" + s);
            if (s == null) return;
            s = s.Replace("'", "");
            s = s.Trim();
            int id=0;
            int.TryParse((s+"0000000000").Substring(0,10), out id);

            if (s == "") return;
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "select top 15 ID,品名,isnull(规格,''),isnull(单位,''),isnull(单价,0) from 物料品种 where 品名 like '" + s + "%' or 简码 like '" + s + "%'";
            if (id > 0)
            {
                Cmd.CommandText += " or id>=" + id;
            }
            Cmd.CommandType = CommandType.Text;
            SqlDataReader Reader = Cmd.ExecuteReader();

            while (Reader.Read())
            {
                context.Response.Write(((int)Reader[0]).ToString("D10") + "\t" + Reader[1] + "\t" + Reader[2] + "\t" + Reader[3] + "\t" + Reader[4] + "\n");
            }
            Reader.Close();
            Conn.Close();
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Dispose();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
